/**
 * 
 */
package sailing.excel;

import java.util.ArrayList;
import java.util.List;

/**
 * @author kevin
 * 
 */
public class ExcelParser {

	private Class<?> entityClass;
	private Class<?> parserClass;
	private List parsedDataList;

	public ExcelParser(Class<?> clazz, Class<?> parserClass) {
		this.entityClass = clazz;
		this.parserClass = parserClass;
	}

	public Translator getTranslator() throws Exception {
		return (Translator) this.newInstance(parserClass);
	}

	public Object getNewInstance() throws Exception {
		return this.newInstance(entityClass);
	}

	public List getParsedDataList() {
		return this.parsedDataList;
	}

	private Object newInstance(Class<?> c) throws Exception {
		try {
			return c.newInstance();
		} catch (InstantiationException e) {
			throw new Exception("Cannot create " + c.getName() + ": " + e.getMessage());
		} catch (IllegalAccessException e) {
			throw new Exception("Cannot create " + c.getName() + ": " + e.getMessage());
		}
	}

	public Class<?> getParserClass() {
		return this.parserClass;
	}

	public void addParsedData(Object object) {
		if (this.parsedDataList == null) {
			this.parsedDataList = new ArrayList();
		}
		this.parsedDataList.add(object);
	}
}
